/*
 * Chrono.cpp
 *
 *  Created on: 1 mars 2013
 *      Author: raph
 */

#include "Chrono.h"

namespace raph
{
void Chrono::start()
    {
    gettimeofday(&m_tv1, nullptr);
    }

unsigned long long int Chrono::stop(TIME time)
    {
    gettimeofday(&m_tv2, nullptr);
    switch (time)
	{
    case TIME::SEC:
	return ((m_tv2.tv_sec - m_tv1.tv_sec) * 1000000L + (m_tv2.tv_usec - m_tv1.tv_usec)) / 1000000;

    case TIME::MSEC:
	return ((m_tv2.tv_sec - m_tv1.tv_sec) * 1000000L + (m_tv2.tv_usec - m_tv1.tv_usec)) / 1000;

    case TIME::USEC:
    default:
	return ((m_tv2.tv_sec - m_tv1.tv_sec) * 1000000L + (m_tv2.tv_usec - m_tv1.tv_usec));
	}
    }
} /* namespace rc */
